home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / playmovie / src / open_url.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  3.1 KB  |  114 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import java.awt.event.*;
  10.  
  11. public class Open_URL extends Dialog implements ActionListener {
  12.     public Open_URL(PlayMovie parent) {
  13.         super(parent, true);
  14.         myPlayMovie = parent;
  15.         
  16.             // This code is automatically generated by Visual Cafe 
  17.             //{{INIT_CONTROLS
  18.         setLayout(null);
  19.         setResizable(false);
  20.         setSize(452,126);
  21.         setFont(new Font("Dialog", Font.PLAIN, 12));
  22.         setBackground (new Color(12632256));
  23.         label2 = new Label("URL:");
  24.         label2.setBounds(18,48,29,18);
  25.         add(label2);
  26.         label1 = new Label ("Please type in an URL for to open:");
  27.         label1.setBounds(54,15,370,23);
  28.         add(label1);
  29.         okButton = new Button();
  30.         okButton.setLabel("OK");
  31.         okButton.setBounds(368,94,60,23);
  32.         add(okButton);
  33.         cancelButton = new Button();
  34.         cancelButton.setLabel("Cancel");
  35.         cancelButton.setBounds(293,94,60,23);
  36.         add(cancelButton);            
  37.         urlTextField = new TextField("file:///... Enter an URL to a movie");
  38.         urlTextField.setBounds(50,42,380,30);
  39.         urlTextField.setFont(new Font("Dialog", Font.PLAIN, 10));
  40.  
  41.         add(urlTextField);
  42.         setTitle("Open URL");
  43.         
  44.         urlTextField.addActionListener(this);
  45.         cancelButton.addActionListener( new ActionListener() {
  46.             public void actionPerformed(ActionEvent event) {
  47.                 dispose();
  48.             }
  49.         });
  50.             
  51.         okButton.addActionListener(new ActionListener() {
  52.             public void actionPerformed(ActionEvent event) {
  53.                 myPlayMovie.createNewMovieFromURL(urlTextField.getText());
  54.                 dispose();
  55.             }
  56.         });
  57.     }
  58.     
  59.     public void addNotify()    {
  60.           // Record the size of the window prior to calling parents addNotify.
  61.         Dimension d = getSize();
  62.  
  63.         super.addNotify();
  64.  
  65.         if (fComponentsAdjusted)
  66.             return;
  67.  
  68.         // Adjust components according to the insets
  69.         setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
  70.         Component components[] = getComponents();
  71.         for (int i = 0; i < components.length; i++)
  72.         {
  73.             Point p = components[i].getLocation();
  74.             p.translate(insets().left, insets().top);
  75.             components[i].setLocation(p);
  76.         }
  77.         fComponentsAdjusted = true;
  78.     }
  79.  
  80.     // Used for addNotify check.
  81.     boolean fComponentsAdjusted = false;
  82.  
  83.     /**
  84.      * Shows or hides the component depending on the boolean flag b.
  85.      * @param b  if true, show the component; otherwise, hide the component.
  86.      * @see java.awt.Component#isVisible
  87.      */
  88.     public void setVisible(boolean b) {
  89.         if(b) {
  90.             Rectangle bounds = getParent().getBounds();
  91.             Rectangle abounds = getBounds();
  92.     
  93.             setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
  94.                  bounds.y + (bounds.height - abounds.height)/2);
  95.         }
  96.         super.setVisible(b);
  97.     }
  98.  
  99.     //{{DECLARE_CONTROLS
  100.     Label label2;
  101.     Label label1;
  102.     Button okButton;
  103.     Button cancelButton;
  104.     TextField urlTextField;
  105.     //}}
  106.     
  107.     private PlayMovie myPlayMovie;
  108.  
  109.     public void actionPerformed(ActionEvent evt) {        
  110.         myPlayMovie.createNewMovieFromURL (urlTextField.getText());
  111.         dispose();
  112.     }
  113. }
  114.